
      <template>
   
 <el-col :span='24'>
      
            <viewTitle text="入院分床" @click='splitbed' style="font-size:20px;margin-bottom:20px" /> 
        <el-col :span='10' >
            <el-form label-position="right" label-width="100px" :model="patientinfo">
  <el-form-item label="原病区">
    <el-input v-model="formLabelAlign.old_bed.icu_name" disabled></el-input>
  </el-form-item>
  <el-form-item label="原房间">
    <el-input v-model="formLabelAlign.old_bed.room_name" disabled></el-input>
  </el-form-item>
  <el-form-item label="原床位">
    <el-input v-model="formLabelAlign.old_bed.bed_name" disabled></el-input>
  </el-form-item>
  <el-form-item label="原住院医生">
    <el-input v-model="patientinfo.bed_doctor.real_name" disabled></el-input>
  </el-form-item>
   <el-form-item label="原床管医生">
    <el-input v-model="patientinfo.doctor.real_name" disabled></el-input>
  </el-form-item>
  <el-form-item label="原责任护士">
    <el-input v-model="patientinfo.nurse.real_name" disabled></el-input>
  </el-form-item>
</el-form>
      </el-col>
       <el-col :span='2'>
          <div style='width:40px'>&nbsp;</div>
      </el-col>
       <el-col :span='10'>
       <el-form label-position="right" label-width="100px" :model="formLabelAlign">
 <el-form-item label='病区'>
              <el-select v-model="formLabelAlign.new_bed.icu_id"  @change="radiochang"  placeholder="病区" style='width:100%'>
    <el-option
      v-for="item in getBuildlist"
      :key="item.value"
      :label="item.name"
      :value="item.id"
      :disabled='item.empty_bed_count==0'
      >
       <span style="float: left">{{ item.name }}</span>
       <span style="float: right; color: #8492a6; font-size: 13px">占 {{ item.full_bed_count }}</span>
      <span style="float: right; color: #8492a6; font-size: 13px">空 {{ item.empty_bed_count }}</span>
    </el-option>
  </el-select>
          </el-form-item>
  <el-form-item label="新房间">
    <el-select v-model="formLabelAlign.new_bed.room_id"
     
      @change='changename2' 
      placeholder="选择房间" 
      style="width:100%">
      <el-option  v-for="(item,index) in buildlist3" :key='index' :label="item.name" :value="item.id">
     
      </el-option>
     
    </el-select>
    
  </el-form-item>
  <el-form-item label="新床位">

     <el-select v-model="formLabelAlign.new_bed.bed_id" @change='changename' placeholder="选择床位" style="width:100%">
      <el-option  v-for="(item,index) in ben_list" :key='index' :label="item.name" :value="item.id"
        :disabled='item.is_lock==1'>

     
    
     </el-option>
     
    </el-select>
    
  </el-form-item>
  <el-form-item label="新住院医生">
    <div class="yisheng">
                      <el-popover
                        placement="bottom-end"
                        v-model="visiblePatient"
                        trigger="focus"
                      >
                        <el-input
                          placeholder="姓名"
                          slot="reference"
                          v-model="formusername"
                          size="mini"
                          style="height:40px"
                        >
                     
                        </el-input>
                        <el-table
                          @row-click="xuanzePatient"
                          height="300"
                          :data="
                            duserlist.filter(
                              data =>
                                !formusername ||
                                data.real_name
                                  .toLowerCase()
                                  .includes(formusername.toLowerCase())
                            )
                          "
                        >
                          <el-table-column
                            width="100"
                            property="number"
                            label="序号"
                          ></el-table-column>

                          <el-table-column
                            width="150"
                            property="real_name"
                            label="姓名"
                          ></el-table-column>
                          <el-table-column
                            width="100"
                            property="dept_name"
                            label="科室"
                          ></el-table-column>

                          <el-table-column
                            width="50"
                            property="gender"
                            label="性别"
                          >
                          <template slot-scope="scope">
       {{scope.row.gender==1?'男':scope.row.gender==2?'女':'未知'}}
      </template>
                          </el-table-column>

                      
                        </el-table>
                      </el-popover>
                    </div>


  </el-form-item>
   <el-form-item label="新床管医生">
       <div class="yisheng">
                      <el-popover
                        placement="bottom-end"
                        v-model="visiblePatient2"
                        trigger="focus"
                      >
                        <el-input
                          placeholder="姓名"
                          slot="reference"
                          v-model="formusername2"
                          size="mini"
                          style="height:40px"
                        >
                          <!-- <i
                            slot="suffix"
                            class="iconfont icon-add-bai "
                            @click.stop="openUserInfo()"
                          ></i> -->
                        </el-input>
                        <el-table
                          @row-click="xuanzePatient2"
                          height="300"
                          :data="
                            duserlist2.filter(
                              data =>
                                !formusername2 ||
                                data.real_name
                                  .toLowerCase()
                                  .includes(formusername2.toLowerCase())
                            )
                          "
                        >
                          <el-table-column
                            width="100"
                            property="number"
                            label="序号"
                          ></el-table-column>

                          <el-table-column
                            width="150"
                            property="real_name"
                            label="姓名"
                          ></el-table-column>
                          <el-table-column
                            width="100"
                            property="dept_name"
                            label="科室"
                          ></el-table-column>

                          <el-table-column
                            width="50"
                            property="gender"
                            label="性别"
                          >
                                   <template slot-scope="scope">
       {{scope.row.gender==1?'男':scope.row.gender==2?'女':'未知'}}
      </template>
                          </el-table-column>

                      
                        </el-table>
                      </el-popover>
                    </div>
  </el-form-item>
  <el-form-item label="新责任护士">
        <div class="yisheng">
                      <el-popover
                        placement="bottom-end"
                        v-model="visiblePatient3"
                        trigger="focus"
                      >
                        <el-input
                          placeholder="姓名"
                          slot="reference"
                          v-model="formusername3"
                          size="mini"
                          style="height:40px"
                        >
                          <!-- <i
                            slot="suffix"
                            class="iconfont icon-add-bai "
                            @click.stop="openUserInfo()"
                          ></i> -->
                        </el-input>
                        <el-table
                          @row-click="xuanzePatient3"
                          height="300"
                          :data="
                            nuserlist.filter(
                              data =>
                                !formusername3 ||
                                data.real_name
                                  .toLowerCase()
                                  .includes(formusername3.toLowerCase())
                            )
                          "
                        >
                          <el-table-column
                            width="100"
                            property="number"
                            label="序号"
                          ></el-table-column>

                          <el-table-column
                            width="150"
                            property="real_name"
                            label="姓名"
                          ></el-table-column>
                          <el-table-column
                            width="100"
                            property="dept_name"
                            label="科室"
                          ></el-table-column>

                          <el-table-column
                            width="50"
                            property="gender"
                            label="性别"
                          >
                                   <template slot-scope="scope">
       {{scope.row.gender==1?'男':scope.row.gender==2?'女':'未知'}}
      </template>
                          </el-table-column>

                      
                        </el-table>
                      </el-popover>
                    </div>

  </el-form-item>
</el-form>
      </el-col>
      </el-col>
</template>

<script>

import ViewTitle from "@/forComponents/viewTitle";
import { getIndex,} from "@/api/account";
import { getAllBedList,getAllIcu,getBed,readHospitalMemberDetail} from "@/api/zhuyanre"
import {getBuild} from "@/api/assets"
import infocrad from './infocrad.vue'

export default {
  name:"costsRecord",
  props: ["patientinfo"],

  data(){
    return {
      formLabelAlign:{
        nurse_id:'',
        doctor_id:'',
        other_doctor_id:'',
        hospital_id:'',
        new_bed:{
          bed_id:'',
          bed_name:"",
          icu_id:"",
          icu_name:"",
          room_id:"",
          room_name:"",
          build_id:"",
          build_name:""
        },
        old_bed:{
            bed_id:'',
          bed_name:"",
          icu_id:"",
          icu_name:"",
          room_id:"",
          room_name:"",
          build_id:"",
          build_name:""
        }
      },
      visiblePatient:false,
       visiblePatient2:false,
        visiblePatient3:false,
      formusername:'',
      formusername2:'',
       formusername3:'',
       icuname: "",
       getBuildlist:[],
        icu_id:'',
      ben_list:[],
      buildlist3:[],
       //护士列表
      nuserlist: [],
      duserlist: [],
      duserlist2:[],
    }
  },
  mounted(){

        this.getIndex(2)
    this.getIndex(3)
    // this.getAllBedList()    
           getAllIcu({level:2}).then(res=>{
      this.getBuildlist=res.data
    })
  },
  created(){
       
        this.getIndex(2)
    this.getIndex(3)
        getAllIcu({level:2}).then(res=>{
      this.getBuildlist=res.data
    })
    this.readHospitalMemberDetail(this.patientinfo.id)
      this.formLabelAlign.old_bed={
                  bed_id:this.patientinfo.bed_id,
                    bed_name:this.patientinfo.room_info?this.patientinfo.room_info[3]:'',
                  icu_id:this.patientinfo.icu_id,

                  icu_name:this.patientinfo.room_info?this.patientinfo.room_info[1]:'',
                  room_id:this.patientinfo.room_id,
                  room_name:this.patientinfo.room_info?this.patientinfo.room_info[2]:'',
                  build_id:this.patientinfo.build_id,
                  build_name:this.patientinfo.room_info?this.patientinfo.room_info[0]:'',
          },
          //      this.formLabelAlign.new_bed={
          //         bed_id:this.patientinfo.bed_id,
          //           bed_name:this.patientinfo.room_info?this.patientinfo.room_info[3]:'',
          //         icu_id:this.patientinfo.icu_id,

          //         icu_name:this.patientinfo.room_info?this.patientinfo.room_info[1]:'',
          //         room_id:this.patientinfo.room_id,
          //         room_name:this.patientinfo.room_info?this.patientinfo.room_info[2]:'',
          //         build_id:this.patientinfo.build_id,
          //         build_name:this.patientinfo.room_info?this.patientinfo.room_info[0]:'',
          // },
         console.log(this.patientinfo,this.formLabelAlign.new_bed)
            // this.formLabelAlign.nurse_id=this.patientinfo.nurse.id
            // this.formusername3=this.patientinfo.nurse.real_name
            //  this.formLabelAlign.other_doctor_id=this.patientinfo.bed_doctor.id
            // this.formusername2=this.patientinfo.bed_doctor.real_name
            // this.formLabelAlign.doctor_id=this.patientinfo.doctor.id
            // this.formusername=this.patientinfo.doctor.real_name
     
    // this.getAllBedList()   
  },
   watch: {
    //  console.log( this.userdata,'000000')
    patientinfo(n) {
      this.readHospitalMemberDetail(n.id)
         this.formLabelAlign.old_bed={
                  bed_id:this.patientinfo.bed_id,
                    bed_name:this.patientinfo.room_info?this.patientinfo.room_info[3]:'',
                  icu_id:this.patientinfo.icu_id,

                  icu_name:this.patientinfo.room_info?this.patientinfo.room_info[1]:'',
                  room_id:this.patientinfo.room_id,
                  room_name:this.patientinfo.room_info?this.patientinfo.room_info[2]:'',
                  build_id:this.patientinfo.build_id,
                  build_name:this.patientinfo.room_info?this.patientinfo.room_info[0]:'',
          },
          //      this.formLabelAlign.new_bed={
          //         bed_id:this.patientinfo.bed_id,
          //           bed_name:this.patientinfo.room_info?this.patientinfo.room_info[3]:'',
          //         icu_id:this.patientinfo.icu_id,

          //         icu_name:this.patientinfo.room_info?this.patientinfo.room_info[1]:'',
          //         room_id:this.patientinfo.room_id,
          //         room_name:this.patientinfo.room_info?this.patientinfo.room_info[2]:'',
          //         build_id:this.patientinfo.build_id,
          //         build_name:this.patientinfo.room_info?this.patientinfo.room_info[0]:'',
          // },
         console.log(n,'000',this.patientinfo),
            // this.formLabelAlign.nurse_id=this.patientinfo.nurse.id
            // this.formusername3=this.patientinfo.nurse.real_name
            //  this.formLabelAlign.other_doctor_id=this.patientinfo.bed_doctor.id
            // this.formusername2=this.patientinfo.bed_doctor.real_name
            // this.formLabelAlign.doctor_id=this.patientinfo.doctor.id
            // this.formusername=this.patientinfo.doctor.real_name
     
            // bed_doctor
            // doctor
            // nurse
           this.getIndex(2)
    this.getIndex(3)
    
    }},
  methods:{
    readHospitalMemberDetail(e){
      readHospitalMemberDetail({id:e}).then(res=>{
        
             var objdata={}
         Object.assign(objdata, res.data.masterInfo, res.data.nodeInfo,res.data.member);
           this.formLabelAlign.new_bed={
                  bed_id:objdata.bed_id,
                    bed_name:objdata.room_info?objdata.room_info[3]:'',
                  icu_id:objdata.icu_id,

                  icu_name:objdata.room_info?objdata.room_info[1]:'',
                  room_id:objdata.room_id,
                  room_name:objdata.room_info?objdata.room_info[2]:'',
                  build_id:objdata.build_id,
                  build_name:objdata.room_info?objdata.room_info[0]:'',
          }
          this.getBuild3(objdata.icu_id)
          this.changename4(objdata.icu_id,objdata.room_id)
           this.formLabelAlign.nurse_id=objdata.nurse.id
            this.formusername3=objdata.nurse_name
             this.formLabelAlign.other_doctor_id=objdata.bed_doctor.id
            this.formusername2=objdata.bed_doctor.real_name
            this.formLabelAlign.doctor_id=objdata.doctor.id
            this.formusername=objdata.doctor_name
            
            this.patientinfo.nurse.real_name=objdata.nurse_name
          
      })
    },
          //      this.formLabelAlign.new_bed={
          //         bed_id:this.patientinfo.bed_id,
          //           bed_name:this.patientinfo.room_info?this.patientinfo.room_info[3]:'',
          //         icu_id:this.patientinfo.icu_id,

          //         icu_name:this.patientinfo.room_info?this.patientinfo.room_info[1]:'',
          //         room_id:this.patientinfo.room_id,
          //         room_name:this.patientinfo.room_info?this.patientinfo.room_info[2]:'',
          //         build_id:this.patientinfo.build_id,
          //         build_name:this.patientinfo.room_info?this.patientinfo.room_info[0]:'',
          // },
        //获取床位
    changename2(e) {
      
    this.formLabelAlign.new_bed.room_name=this.bingqu(e)
    console.log(this.formLabelAlign.new_bed.room_name)
      var data_t = {
        icu_id: this.icu_id,
        is_lock: "2",
        room_id:e
        
      };
      getBed(data_t)
        .then(res => {
          let data = res.data.list;
       
          this.ben_list=data
        })
        .catch(e => {});
    },
      changename4(a,e) {
      
    this.formLabelAlign.new_bed.room_name=this.bingqu(e)
    console.log(this.formLabelAlign.new_bed.room_name)
      var data_t = {
        icu_id: a,
        is_lock: "",
        room_id:e
        
      };
      getBed(data_t)
        .then(res => {
          let data = res.data.list;
       
          this.ben_list=data
        })
        .catch(e => {});
    },
    bingqu(e){
           var art = "";

         this.buildlist3.map(function(value,i,array){
            
            if (value.id == e) {
          art = value.name;
        }
        
       })
        return art;  
    //     this.buildlist3.forEach((item)=>{
    
    //    if(item.id == e){
       
    //       //  console.log(art)
    //         return item.name
    //      }
      
    //  });
    },
    getBuild3(id){
       var data_t={
        level:'3',
        pid:id 
      }
      getBuild(data_t).then(res=>{
            console.log(res)
            this.buildlist3=res.data.list
      
           
      })
    },
    //
    radiochang(e){
     
         this.formLabelAlign.new_bed.icu_name=this.fang(e)
              this.getBuild3(e)  
    },
    fang(e){
         var art = "";

         this.getBuildlist.map(function(value,i,array){
            
            if (value.id == e) {
          art = value.name;
        }
        
       })
        return art;  
    //     this.getBuildlist.forEach((item)=>{
    //        var art=''
    //    if(item.id == e){
    //        art= item.name
    //         console.log(art)
    //          return art

    //      }
     
       
    //  });
    },
        xuanzePatient(item) {
      console.log("item", item);
    this.formusername=item.real_name
    this.formLabelAlign.doctor_id=item.id
    this.visiblePatient = false;
    },
       xuanzePatient2(item) {
      console.log("item", item);
    this.formusername2=item.real_name
    this.formLabelAlign.other_doctor_id=item.id
    this.visiblePatient2 = false;
     
    },
       xuanzePatient3(item) {
      console.log("item", item);
    this.formusername3=item.real_name
    this.formLabelAlign.nurse_id=item.id
    this.visiblePatient3 = false;
    },
  
        //选择床位
    changename(e){
          console.log(e)
         
         this.formLabelAlign.new_bed.bed_name=this.chuang(e)
    },
    chuang(e){
          var art = "";

         this.ben_list.map(function(value,i,array){
            
            if (value.id == e) {
          art = value.name;
        }
        
       })
        return art;  
    //     this.ben_list.forEach((item)=>{
    //         var art=''
    //    if(item.id == e){
    //        art= item.name
    //         console.log(art)
    //         return art
    //      }
      
       
    //  });
    },
        //获取医生
          getIndex(type){
       var data_y={
         user_type:type,
         page:1,
         limit:3000,
        //  status:1
       }
 
      getIndex(data_y)
      .then(res=>{
        if(type==3){
          this.nuserlist = res.data.list
        }else if(type==2){
          this.duserlist = res.data.list
          this.duserlist2=JSON.parse(JSON.stringify(this.duserlist))
        }
        console.log(this.duserlist)
      })
      .catch(e=>{
    
        this.$message({
          message:e.message,
          type: 'error'
        });
      })
    },
    splitbed(){
        this.formLabelAlign.hospital_id=this.patientinfo.id
        // this.formLabelAlign.new_bed.room_name=this.formLabelAlign.new_bed.room_name
        //  this.formLabelAlign.new_bed.icu_name=this.formLabelAlign.new_bed.icu_name
        // this.formLabelAlign.new_bed.bed_name=this.formLabelAlign.new_bed.bed_name
        this.$emit('splitbed',this.formLabelAlign)
    }

  },
  components:{

    ViewTitle,
    infocrad

  }
}
</script>

<style lang='scss' scoped>
.yisheng>>>.el-input--mini .el-input__inner {
    height: 40px !important;
    width: 100% !important;
    display: inline-block !important;
}
.separate {
    .dialog-text {
        font-size: 16px;
        margin-bottom: 16px;
        display: flex;
        justify-content: space-between;
        span{
          display: inline-block;

          text-indent:1em
        }
    }
}

</style>